/*
 * SharedMemory.cpp
 *
 *  Created on: Nov 2, 2013
 *      Author: vladimir
 */

#include "SharedMemory.hpp"

#include "AccessType.hpp"
#include "ShMem.hpp"
#include "Mmap.hpp"


namespace vjipc
{


struct SharedMemory::Imp
{
	Imp( const vjipc::AccessType & accessType,
	     const std::string & name,
	     const unsigned int lenght );


	const std::string fullShmName;
	ShMem shMemFileAccess;
	Mmap memoryAccess;

};

SharedMemory::Imp::Imp( const vjipc::AccessType & accessType,
                        const std::string & name,
                        const unsigned int lenght ) :
		fullShmName( "/" + name ),
		shMemFileAccess( accessType, name, lenght ),
		memoryAccess( accessType, shMemFileAccess.GetFileDescriptor(), lenght )
{
}


SharedMemory::SharedMemory( const ::vjipc::AccessType& accessType,
							const std::string& name,
							const unsigned int lenght ) :
								pimpl( new Imp( accessType, name, lenght ) )
{
}

SharedMemory::~SharedMemory()
{
}

void* SharedMemory::GetSharedMemoryPtr() const
{
	return pimpl->memoryAccess.GetAddressToMmappedRegion();
}

} /* namespace vjipc */
